﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DCTLib.Common;
using System.Data;

namespace DCTAccess.Business.Percent
{
    public class PercentFilter
    {
        #region Private Percents
            private int _configID = -1;
            private int _numOfPeople = -1;
            private decimal _percentConfig = 0;
            private string _sortOrder = " ORDER BY NumOfPeople ASC ";
        #endregion

        #region Public Properties
            public decimal PercentConfig
            {
                get { return _percentConfig; }
                set { _percentConfig = value; }
            }
            public int NumOfPeople
            {
                get { return _numOfPeople; }
                set { _numOfPeople = value; }
            }
            public int ConfigID
            {
                get { return _configID; }
                set { _configID = value; }
            }

            private string SelectAll
            {
                get
                {
                    StringBuilder sql = new StringBuilder();
                    sql.Append("SELECT ConfigID,NumOfPeople,[percent] ");                    
                    sql.Append("FROM Configs ");
                    sql.Append("WHERE Active = 1 ");
                    return sql.ToString();
                }
            }
            #endregion

            public DataTable GetConfigPercent()
            {
                SQLHelper sqlHelper = new SQLHelper();
                sqlHelper.SwitchCommandType(CommandType.Text);
                StringBuilder sql = new StringBuilder(SelectAll);

                if (_configID != -1)
                {
                    sql.Append("AND " + IntegerCompareSQLBuilder.GetSQL("ConfigID", IntegerCompareTypes.Equals, "@ConfigID"));
                    sqlHelper.AddParameter("@ConfigID", _configID);
                }                

                sql.Append(_sortOrder);
                return sqlHelper.GetDataTable(sql.ToString());

            }
    }
}
